package com.btpn.custody.dao.hibernate;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.btpn.custody.dao.ITL_GLOBAL;
import com.btpn.custody.entity.TL_GLOBAL;

@Repository("TL_GLOBAL_DaoHibernate")
public class TL_GLOBAL_DAO implements ITL_GLOBAL {

	protected HibernateTemplate template = null;
	
	@Autowired @Required
	public void setSessionFactory(SessionFactory sessionFactory) {
		template = new HibernateTemplate(sessionFactory);
	}
	
	@Override
	public TL_GLOBAL get(Long id) {
		return template.get(TL_GLOBAL.class, id);
	}

	@Override
	public List<TL_GLOBAL> findAll() {
		return template.loadAll(TL_GLOBAL.class);
	}

	@Override
	public Integer getCount() {
		return Integer.valueOf(findAll().size());
	}

	@Override
	public Serializable create(TL_GLOBAL global) {
		return template.save(global);		
	}

	@Override
	public void delete(Long id) {
		template.delete(get(id));
	}

	@Override
	public Serializable create(String actionClass, String action, String group,	String user, String note) {
		TL_GLOBAL global = new TL_GLOBAL(actionClass, action, group, user, note);
		
		return template.save(global);
	}
}